<template>
  <div>
    <van-cell-group>
      <van-field v-model="user.phone" label="账号" placeholder="请输入用户名" />
    </van-cell-group>

     <van-cell-group>
      <van-field v-model="user.password" label="密码" placeholder="请输入用户名" />
    </van-cell-group>

    <!-- <div>账号：<input type="text" v-model="user.phone" /></div>
    <div>密码：<input type="text" v-model="user.password" /></div> -->
    <van-button @click="login" type="primary" class="btn" block>登录</van-button>
    <br>

    <!-- 路由导航 -->
    <router-link to="/register">去注册</router-link>
  </div>
</template>

<script>
import { reqLogin } from "../../http/http";
import { Toast } from "vant";
export default {
  data() {
    return {
      user: {
        phone: "",
        password: "",
      },
    };
  },
  methods: {
    login() {
      reqLogin(this.user).then((res) => {
        // console.log(res);
        if (res.data.code === 200) {
          Toast(res.data.msg);
          //存用户的信息
          localStorage.setItem("userInfo", JSON.stringify(res.data.list));
          //存储用户登录成功的标识
          localStorage.setItem("isLogin", 1);
          // 跳转首页
          this.$router.push("/index/home");
        } else {
          // 报错
          Toast(res.data.msg);
        }
      });
    },
  },
};
</script>

<style scoped>

</style>